Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Policy Agent Example #207

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

lawrenae
Copy link

This is supporting material for how to create a cloud run instance where routes are authorized by Open Policy Agent.

Note: this solution includes building a custom docker container, and so part of the CI steps is using an Artifact Registry repository called docker in us-central1

Permissions required on the cloud build service account:

  • Cloud Run Admin
  • roles/artifactregistry.createOnPushRepoAdmin

Feedback most welcome!

@lawrenae lawrenae requested a review from a team as a code owner August 30, 2023 16:55
@product-auto-label product-auto-label bot added api: run Issues related to the GoogleCloudPlatform/cloud-run-samples API. samples Issues that are directly related to samples. labels Aug 30, 2023
@pattishin pattishin self-assigned this Sep 21, 2023
@pattishin pattishin self-requested a review October 20, 2023 21:18
@glasnt
Copy link
Contributor

glasnt commented Nov 2, 2023

/gcbrun

@pattishin
Copy link
Contributor

/gcbrun

Copy link
Contributor

@pattishin pattishin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the sample and patience @lawrenae! 👍🏼 Do let me know if you have any queries concerning the comments I have added.

# Prerequsites

* An up to date gcloud SDK installed
* [opa](https://www.openpolicyagent.org/docs/latest/) installed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [opa](https://www.openpolicyagent.org/docs/latest/) installed
* [opa](https://www.openpolicyagent.org/docs/latest/cli/) installed

Tweaking url to point directly to the cli page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adding:


The goal is to use a simple HTTP web server that accepts any HTTP GET request that you issue and echoes the OPA decision back as text. OPA will fetch policy bundles from a simple bundle server. OPA, the bundle server, and the web server will be run as containers in Cloud Run. In a production environment, you likely will have a different bundle server, but it's convenient to package it together here.

# Prerequsites
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Prerequsites
# Prerequisites

docker push us-central1-docker.pkg.dev/<CLOUD_PROJECT>/docker/<IMAGE_NAME>
```

Note: We assume Google Cloud Artifact Registry in this tutorial but any registry accessible to Cloud Run will work
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, do you mind moving this up the prereqs or in a section of required gcp apis like the sister sample https://github.com/GoogleCloudPlatform/cloud-run-samples/tree/main/multi-container/hello-nginx-sample#enable-required-apis?

* Create a custom bundle server with [Dockerfile.nginx](./Dockerfile.nginx) and [nginx.conf.template](./nginx.conf.template) with the following command:

```bash
docker build -f Dockerfile.nginx -t us-central1-docker.pkg.dev/<CLOUD_PROJECT>/docker/<IMAGE_NAME> .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind replacing this with the Cloud Build equivalent? Dockerfile can still be leveraged.


# 1. Create and push a custom bundle server image

* Follow [Step 1](https://www.openpolicyagent.org/docs/latest/http-api-authorization/#1-create-a-policy-bundle) in the original tutorial, resulting in creating two files called `example.rego` and `bundle.tar.gz`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on itemizing these step by step here? It'll make the README easier to follow and the steps on the site could change later down the line without us realizing.

@pattishin
Copy link
Contributor

pattishin commented Dec 5, 2023

Hi @lawrenae! Just a friendly ping - happy to chat more about the sample.

@glasnt
Copy link
Contributor

glasnt commented Jun 19, 2024

/gcbrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: run Issues related to the GoogleCloudPlatform/cloud-run-samples API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants